# Maintainer: Leonidas Spyropoulos <artafinde@archlinux.org>
# Contributor: David Runge <dvzrv@archlinux.org>

pkgname=mtxclient
pkgver=0.9.2
pkgrel=4
pkgdesc="Client API library for the Matrix protocol"
arch=('loong64' 'x86_64')
url="https://nheko.im/nheko-reborn/mtxclient"
license=('MIT')
depends=(gcc-libs glibc)
makedepends=(cmake coeurl fmt libolm meson nlohmann-json openssl re2 spdlog git)
checkdepends=(gmock gtest)
provides=(libmatrix_client.so)
source=("git+https://nheko.im/nheko-reborn/mtxclient.git?signed#tag=v${pkgver}"
        "0.6.0_remove_network_tests.patch")
sha256sums=('SKIP'
            '2edba127593d172b5e535a4f0058d26a47a67f8b4c2d0cef9d6eac07e17eba3e')
b2sums=('SKIP'
        'af9e62223b59cfae2b711420944612a40d8ff7e87d188c3ccdb3a628310458df498cba70786bcb5cb35bce7e82940249ade31003e7418dcaa6c58cde33e6b25f')
validpgpkeys=('D58B462425A6A37125C6FEDB9206AE1B231E05BB') # Nicolas Werner @deepbluev7 https://nheko.im/deepbluev7.gpg

prepare(){
  cd "$pkgname"
  # https://github.com/Nheko-Reborn/mtxclient/issues/93
  patch -Np1 < "../0.6.0_remove_network_tests.patch"
}

build() {
  cmake \
    -Bbuild \
    -GNinja \
    -S "$pkgname" \
    -DCMAKE_BUILD_TYPE='None' \
    -DCMAKE_INSTALL_PREFIX='/usr' \
    -DCMAKE_INSTALL_LIBDIR='lib' \
    -DBUILD_LIB_EXAMPLES=OFF \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_LIB_TESTS=ON \
    -DBUILD_LIB_EXAMPLES=OFF \
    -Wno-dev
  cmake --build build --verbose
}

check() {
  ninja test -C build
}

package() {
  depends+=(
    coeurl libcoeurl.so
    fmt libfmt.so
    libolm libolm.so
    openssl libcrypto.so
    re2 libre2.so
    spdlog libspdlog.so
  )
  DESTDIR="${pkgdir}" cmake --install build
  install -Dm644 $pkgname/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

# vim:set ft=sh sw=2 sts=2 et:
